'use strict';
var pay = require('../utils/pay');

module.exports = {
  callwxPay: function(orderId, offlineSalesForm, done) {
    var wxSession = wx.getStorageSync('sessionId');
    pay.callPay({
      'order_id':orderId,
      'wx_session':wxSession,
      success:function(res){
        if (done) {
          done()
        }
        wx.redirectTo({
          url: '../payment-success/success?order_id=' + orderId+'&offlineSalesForm=' + offlineSalesForm
        })
      },
      fail:function(res){
        if (done) {
          done()
        }
        if (res.errMsg == "requestPayment:fail cancel"){
          // wx.navigateBack({
          //   delta: 1
          // })
          return false;
        }           
        wx.redirectTo({
          url: '../payment-error/error?order_id='+orderId
        }) 
      }
    });
  }
}